﻿Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
Imports System.Data

Public Class cls_errores

    Private _id As Integer
    Private _desc As String
    Private _clase As String
    Private _metodo As String

    Public Property id() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property
    Public Property desc() As String
        Get
            Return _desc
        End Get
        Set(ByVal value As String)
            _desc = value
        End Set
    End Property
    Public Property clase() As String
        Get
            Return _clase
        End Get
        Set(ByVal value As String)
            _clase = value
        End Set
    End Property
    Public Property metodo() As String
        Get
            Return _metodo
        End Get
        Set(ByVal value As String)
            _metodo = value
        End Set
    End Property

    Sub New()
        _id = 0
        _desc = ""
        _clase = ""
        _metodo = ""
    End Sub

    Public Function registraErrorEnLog() As String
        Dim path As String = System.Configuration.ConfigurationManager.AppSettings("LogErrores").ToString()

        If Right(path, 1) <> "\" Then
            path = path + "\"
        End If
        Dim escritor As StreamWriter
        If (Directory.Exists(path) = False) Then
            Directory.CreateDirectory(path)
        End If

        escritor = File.AppendText(path + "LogError" + Now().ToString("yyyyMMdd") + ".log")
        escritor.WriteLine(Now().ToString("dd-MM-yyyy") & _
                               Chr(9) & Now().ToString("HH:mm:ss") & _
                               Chr(9) & _id & _
                               Chr(9) & _desc & _
                               Chr(9) & _clase & _
                               Chr(9) & _metodo)
        escritor.Flush()
        escritor.Close()

        Dim v_str_respuesta As String = "Se ha producido un error, por favor comuníquese con soporte de la aplicación identificando archivo LogError" + Now().ToString("yyyyMMdd") + ".log"
        _desc = v_str_respuesta
        _clase = ""
        _metodo = ""
        Return v_str_respuesta
    End Function
End Class
